<?php
// 获取历史订单信息
// header("content-type:text/html;charset=utf-8");
include_once("conn.php");

$uid = $_SESSION['USERINFOS']['uid'];

$sql = "SELECT * FROM tb_order_info 
            LEFT JOIN tb_goods_info 
            ON tb_order_info.g_id = tb_goods_info.g_id 
            WHERE tb_order_info.uid = '" . $uid . "'
            AND o_status != 0 
            AND o_status != 1 
            ORDER BY tb_order_info.id DESC";
$result = mysqli_query($conn, $sql);
if ($result) {
    if (mysqli_num_rows($result) > 0) {
        while ($row = mysqli_fetch_assoc($result)) {
            $s = '';
            if ($row['o_status'] == 2) {
                $s = "<td style='color:green'>订单完成</td>";
            } else {
                $s = "<td style='color:tomato'>订单取消</td>";
            }
            echo "
                <tr>
                    <th scope='row'>" . $row['o_id'] . "</th>
                    <td>" . $row['o_name'] . "</td>
                    <td>" . $row['o_address'] . "</td>
                    <td>" . $row['o_phone'] . "</td>
                    <td>" . $row['g_name'] . "</td>
                    <td>" . $row['o_num'] . "</td>
                    <td>" . $row['o_price'] . "</td>
                    <td>" . $row['o_pay'] . " 元</td>
                    <td>" . $row['o_begintime'] . "</td>
                    <td>" . $row['o_shippedtime'] . "</td>
                    <td>" . $row['o_endtime'] . "</td>" . $s . "
                </tr>
                ";
        }
    } else {
        echo "<tr><td colspan='12'>暂无历史订单信息</td></tr>";
    }
} else {
    echo "<tr><td colspan='12'>查询历史订单信息失败</td></tr>";
}
